﻿DECLARE @last_id_in_employeetask INTEGER;

SET @last_id_in_employeetask = (SELECT task_id FROM EmployeeTask Where emp_id = '18' and part LIKE 'Creator');

IF NOT EXISTS( 
SELECT * FROM EmployeeTask Where task_id = @last_id_in_employeetask and emp_id = '18')
BEGIN
INSERT INTO TaskTable(task_name, task_desciption, status_id) Values('Test taskname', 'test task description', '1')
DECLARE @last_id_in_tasktable INTEGER;
SET @last_id_in_tasktable = SCOPE_IDENTITY();
INSERT INTO EmployeeTask(task_id,emp_id,part) VALUES (@last_id_in_tasktable, '18', 'Creator');

END 

